<template> 
    <el-card class="form-container" shadow="never">
        <el-form :model="${modelNameLowerCamel}"  ref="${modelNameLowerCamel}From" label-width="150px">
    <#list modeListDetails as item>
             <#if "${item.type}"?contains("datetime")>
             <#else >
                 <#if "${item.name}"?contains("logo")||"${item.name}"?contains("Logo")
                    ||"${item.name}"?contains("Photo")||"${item.name}"?contains("photo")
                    ||"${item.name}"?contains("Img")||"${item.name}"?contains("img")
                    ||"${item.name}"?contains("Image")||"${item.name}"?contains("image")
                    ||"${item.name}"?contains("pic")||"${item.name}"?contains("Pic")>
            <el-form-item label="${item.remark}">
                <single-upload v-model="${modelNameLowerCamel}.${item.name}"></single-upload>
            </el-form-item>
                 <#else>
            <el-form-item label="${item.remark}">
                <el-input v-model="${modelNameLowerCamel}.${item.name}"></el-input>
            </el-form-item>
                 </#if>
             </#if>
    </#list>
            <el-form-item>
                <el-button type="primary" @click="onSubmit('brandFrom')">提交</el-button>
                <el-button v-if="!isEdit" @click="resetForm('brandFrom')">重置</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</template>
<script>
    import {create${modelNameUpperCamel}, update${modelNameUpperCamel}, fetch${modelNameUpperCamel}ById,} from '@/api/${modelNameLowerCamel}'
    import SingleUpload from '@/components/Upload/singleUpload'

    const default${modelNameUpperCamel} = {
    <#list modeListDetails as item>
        <#if "${item.type}"?contains("int")||"${item.type}"?contains("bigint")>
        ${item.name}:0,
        <#else >
        ${item.name}:"",
        </#if>
    </#list>
    };
    export default {
        name: '${modelNameUpperCamel}Detail',
        components: {SingleUpload},
        props: {
            isEdit: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
            ${modelNameLowerCamel}: Object.assign({}, default${modelNameUpperCamel})
            }
        },
        created() {
            if (this.isEdit) {
                fetch${modelNameUpperCamel}ById(this.$route.query.id).then(response => {
                    this.${modelNameLowerCamel} = response.data;
                });
            } else {
                this.${modelNameLowerCamel} = Object.assign({}, default${modelNameUpperCamel});
            }
        },
        methods: {
            onSubmit(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$confirm('是否提交数据', '提示', {confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
                        }).then(() => {
                            if (this.isEdit) {
                                update${modelNameUpperCamel}(this.$route.query.id, this.${modelNameLowerCamel}).then(response => {
                                    this.$refs[formName].resetFields();
                                    this.$message({message: '修改成功', type: 'success', duration: 1000});
                                    this.$router.back();
                                });
                            } else {
                                create${modelNameUpperCamel}(this.${modelNameLowerCamel}).then(response => {
                                    this.$refs[formName].resetFields();
                                    this.${modelNameLowerCamel} = Object.assign({}, default${modelNameUpperCamel});
                                    this.$message({message: '提交成功', type: 'success', duration: 1000});
                                });
                            }
                        });

                    } else {
                        this.$message({message: '验证失败', type: 'error', duration: 1000});
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                this.${modelNameLowerCamel} = Object.assign({}, default${modelNameUpperCamel});
            }
        }
    }
</script>
<style>
</style>


